//
//  ProprieterViewController.m
//  LazyCat
//
//  Created by zhanshu on 15/9/8.
//  Copyright (c) 2015年 zhanshu. All rights reserved.
//

#import "ProprieterViewController.h"
#import "BaseTabBarViewController.h"
#import "ShopCommonModel.h"
@interface ProprieterViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *dataArr;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation ProprieterViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.view.backgroundColor = BackColor;
    [self initNav:_titleStr doBack:YES];
    dataArr = [[NSMutableArray alloc] init];
    _tableView.backgroundColor = BackColor;
    _tableView.tableFooterView = [[UIView alloc] init];
    
    [self getShopMess];
}
//- (void)setCityID:(NSString *)cityID {
//    [self getShopMess];
//}
#pragma mark -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return dataArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *Cell = @"cell";
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:Cell];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:Cell];
        cell.accessoryType =  UITableViewCellAccessoryDisclosureIndicator;
    }
    if (dataArr.count > 0) {
        ShopCommonModel *model = dataArr[indexPath.row];
        cell.textLabel.text = model.name;
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    ShopCommonModel *model = dataArr[indexPath.row];
    [AppData share].proprieter = model.name;
    [ShopCommonModel saveShopMess:model];

    if ([AppData share].doFirst) {
        BaseTabBarViewController *baseTab = [[BaseTabBarViewController alloc] init];

        [self.navigationController pushViewController:baseTab animated:YES];
    }else {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}
#pragma mark -获取数据
- (void)getShopMess {
    NSString *url = [NSString stringWithFormat:GetShopByCityID,[NSString stringWithFormat:@"%@",_cityID],[Utils md5SignStr]];
    [NTNetUtil sendRequestWithUrl:url requestName:nil method:NTRequestMethodGET parameters:nil block:^(NTHttpRequest *networkRequest, NSError *error) {
        NSDictionary *dic = networkRequest.responseData;
        NSString *r = dic[@"r"];
        if ([r isEqualToString:@"T"]) {
            NSArray *arr = dic[@"shops"];
            for (int i = 0; i < arr.count; i ++) {
                ShopCommonModel *model = [RMMapper objectWithClass:[ShopCommonModel class] fromDictionary:arr[i]];
                [dataArr addObject:model];
            }
            if (arr.count == 0) {
                [[MessShowView share] showWithMess:@"此城市下没有社区"];
            }
        }else {
            [[MessShowView share] showWithMess:dic[@"m"]];
        }
        [_tableView reloadData];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
